import time
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from pages.page_background_login import BackLogin
from pages.page_login import Login
from config import *


@pytest.fixture
def web_driver():
    """前后置操作
    """
    path = r"D:\tools\python\chromedriver.exe"  # 定义驱动路径
    ser = Service(executable_path=path)  # 实例化Chrome浏览器服务驱动
    driver = webdriver.Chrome(service=ser)  # 打开Chrome浏览器
    # 设置浏览器最大化
    driver.maximize_window()
    driver.implicitly_wait(10)  # 全局隐式等待
    yield driver
    time.sleep(2)
    driver.quit()


@pytest.fixture()
def front_login(web_driver):
    """前台登录
    """
    login_page = Login(web_driver)
    login_page.open_url()
    login_page.login('13810012011', 'abc123')


@pytest.fixture()
def queen_login(web_driver, username=USERNAME, password=PASSWORD, valicode=VALICODE):
    """
    后台登录
    :param web_driver:
    :return:
    """
    login_page = BackLogin(web_driver)
    login_page.open_url()
    login_page.back_login(username, password, valicode)
